package com.easyadmin.entity.po;

import com.easyadmin.entity.enums.DateTimePatternEnum;
import com.easyadmin.entity.enums.OpResultEnum;
import com.easyadmin.entity.enums.OperModuleEnum;
import com.easyadmin.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;


/**
 * 操作日志
 */
@SuppressWarnings("serial")
public class SysOperationLog implements Serializable {


    /**
     *
     */
    private Integer id;

    /**
     * 操作人ID
     */
    private Integer userId;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 操作对象
     */
    private Integer opObject;

    /**
     * 操作描述
     */
    private String opDescription;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private java.util.Date createTime;

    /**
     * 操作结果
     */
    private Integer opResult;

    /**
     * 错误信息
     */
    private String errorMsg;

    /**
     * ip
     */
    private String ip;

    /**
     * ip 所在地址
     */
    private String ipAddress;

    private String opResultName;

    private String opObjectName;

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return this.id;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Integer getUserId() {
        return this.userId;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserName() {
        return this.userName;
    }

    public void setOpObject(Integer opObject) {
        this.opObject = opObject;
    }

    public Integer getOpObject() {
        return this.opObject;
    }

    public void setOpDescription(String opDescription) {
        this.opDescription = opDescription;
    }

    public String getOpDescription() {
        return this.opDescription;
    }

    public void setCreateTime(java.util.Date createTime) {
        this.createTime = createTime;
    }

    public java.util.Date getCreateTime() {
        return this.createTime;
    }

    public void setOpResult(Integer opResult) {
        this.opResult = opResult;
    }

    public Integer getOpResult() {
        return this.opResult;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getOpResultName() {
        OpResultEnum opResultEnum = OpResultEnum.getStatusByType(opResult);
        return opResultEnum == null ? "" : opResultEnum.getDescription();
    }

    public void setOpResultName(String opResultName) {
        this.opResultName = opResultName;
    }

    public String getOpObjectName() {
        OperModuleEnum moduleEnum = OperModuleEnum.getOperObjectByType(opObject);
        return moduleEnum == null ? "" : moduleEnum.getDescription();
    }

    public void setOpObjectName(String opObjectName) {
        this.opObjectName = opObjectName;
    }

    @Override
    public String toString() {
        return "id:" + (id == null ? "空" : id) + "，操作人ID:" + (userId == null ? "空" : userId) + "，用户名:" + (userName == null ? "空" : userName) + "，操作对象:" + (opObject == null ? "空" : opObject) + "，操作描述:" + (opDescription == null ? "空" : opDescription) + "，创建时间:" + (createTime == null ? "空" : DateUtil.format(createTime, DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern())) + "，操作结果:" + (opResult == null ? "空" : opResult) + "，错误信息:" + (errorMsg == null ? "空" : errorMsg);
    }
}
